home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / AIFF_DSP_v15 folder / AIFF_DSP / chebyshev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-31  |  1.8 KB  |  76 lines  |  [TEXT/KAHL]

  1. /*
  2. FILE:    chebyshev.c
  3. PROJECT: Ford grant DSP
  4. AUTHOR:  Ben Denckla
  5. COMMENT: nonlinear transfer function using Chebyshev polynomials of
  6.          user-specified order.
  7. */
  8.  
  9. #include "aiff.h"
  10. #include "sintab.h" // has the useful GETNUMRANGE() macro
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14.  
  15. #define MAXORDER   16                // MAX. ORDER of chebyshev polynomial
  16. #define CILOG2     11                // see below
  17. #define CHECK_INC  ( 1U << CILOG2 )  // period of progress report,
  18.                                      // in table entries
  19. int take_input = 1, make_output = 1;
  20.  
  21. static short *xferfunc;
  22.  
  23. void init_process( void ) {
  24.     short i, t, *txferfunc, order;
  25.     double twox, *tp;
  26.     double p[MAXORDER] = {1};
  27.  
  28.     if ( (ba.com.wdsi < 9) || (ba.com.wdsi > 16) )
  29.         err( "Cannot process a file with this word size" );
  30.  
  31.     if (!(xferfunc = malloc( 0x20000 )))
  32.         err( "Couldn't allocate transfer function table memory" );
  33.     
  34.     GETNUMRANGE( "order", "%hd", "%hd", order, 1, MAXORDER );
  35.     
  36.     puts( "Generating transfer function table..." );
  37.     for (i=0; i < 0x10000 / CHECK_INC; i++) fputc( '*', stderr );
  38.     fputc( '\n', stderr ); fflush( stderr );
  39.  
  40.     txferfunc = xferfunc;
  41.     i = -0x8000;
  42.     do {
  43.         if (!(i % CHECK_INC)) {    // progress report
  44.             fputc( '*', stderr ); fflush( stderr );
  45.         }
  46.         tp = &p[1];
  47.         *tp = (double) i / 0x8000;
  48.         twox = *tp * 2;
  49.  
  50.         for ( t=2; t<=order; t++ ) {
  51.             tp++;
  52.             *tp = *(tp-1) * twox  -  *(tp-2);
  53.         }
  54.         
  55.         *txferfunc++ = *tp * 0x7FFE; // 1
  56.     } while ( i++ < 0x7FFF);
  57.     
  58.     puts( "\n\n" );
  59. }
  60. // 1. assumes |*tp|/1 <= 0x7FFF/0x7FFE
  61.  
  62. void term_process ( void ) {
  63.     free( xferfunc );
  64. }
  65.  
  66. void process_samdat ( long buflen ) {
  67.     register short *td, *endd, *txferfunc;
  68.     
  69.     td        = d;
  70.     txferfunc = xferfunc;
  71.     endd      = &td[ba.com.chan * buflen];
  72.     
  73.     do {
  74.         *td++ = txferfunc[ 0x8000 + *td ];
  75.     } while ( td < endd );
  76. }